$(function(){	
	//快递列表
	expressList();
	//选择快递
	$('.delivery .content').click(function(){
		var show = $(this).siblings('.way-list').css('display');
		show == 'none' ? show = 'block' : show = 'none';
		$(this).siblings('.way-list')
		.css('display',show)
		.css('z-index','10');
		$(this).siblings('.way-list').find('span').css('display',show);
		
	});
	//选择快递方式
	$('.delivery .way-list span').click(function(){
		var $way = $(this).text();
		$(this).addClass('red').siblings().removeClass('red');
		$(this).parent().siblings('.content').text($way);
		$(this).parent().css('display','none').css('z-index','1');
		//记录快递费用
		$(this).parents(".delivery").siblings('.freight').find(".expressFee").text($(this).attr("fee"));
		$(this).parent().siblings('.content').attr("id",$(this).attr("id")); //记录快递ID
		//重新计算价格
		calculatePrice();
	});
});



//快递列表
function expressList(){
	var url = rootPath + "/order/expressList";
	var expressList = CommnUtil.ajax(url,{},"html");
	console.log(expressList);
	var list = JSON.parse(expressList).data;
	//	alert($("#expressList"));
		$(".selectS .delivery .way-list").each(function(){
			for(var i =0; i< list.length; i++){
				var express = list[i];
				var expressPrice=parseFloat(express.fee);
				var red ='';
				if(i== 0){
					$(".expressFee").text(expressPrice.toFixed(2));
					$(this).siblings('.content').text(express.name);
					calculatePrice();	//重新计算价格	
					red = 'class="red"';
				}
			   $(this).append("<span "+red +"id='"+express.id+"' fee='"+ expressPrice.toFixed(2) +"'>"+express.name+"</span>");

			}
		});
}